﻿using HR.Config;
using HR.IService;
using HR.Models;

namespace HR.Service
{
    public class Job_setService : IJob_setService
    {
        private readonly HRDBContext db;

        public Job_setService(HRDBContext db)
        {
            this.db = db;
        }
        public Task<Paging<config_public_char>> JobSetFill()
        {
            return Task.Run(() =>
            {
                List < config_public_char > list = db.config_public_chars.Where(cpc=>cpc.attribute_kind=="职称").ToList();
                Paging<config_public_char> pg = new Paging<config_public_char>()
                {
                    tabs = list,
                    rows = list.Count
                };
                return pg;
            });
        }

        public Task<int> JobSetAdd(config_public_char cpc)
        {
            return Task.Run(() =>
            {
                cpc.attribute_kind = "职称";
                db.config_public_chars.Add(cpc);
                return db.SaveChanges();
            });
        }
        public Task<int> JobSetUpdate(config_public_char cpc)
        {
            return Task.Run(() =>
            {
                config_public_char? pc = db.config_public_chars.Find(cpc.pbc_id);
                pc.attribute_name = cpc.attribute_name;
                return db.SaveChanges();
            });
        }

        public Task<int> JobSetDelete(short cpcid)
        {
            return Task.Run(() =>
            {
                config_public_char? pc = db.config_public_chars.Find(cpcid);
                db.config_public_chars.Remove(pc);
                return db.SaveChanges();
            });
        }
    }
}
